package lord.js.wods;

import handle.functions.MessageUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import response.MessageType.Message_Text;

public class Deal {
	
	public static String DO(HttpServletRequest request) {
		String respContent = "WTF";
		String respXMLString = "";
		try {
			Map<String, String> map = MessageUtil.parseXML(request);
			String m_fromUserName = map.get("FromUserName");
			String m_toUserNameString = map.get("ToUserName");
			String m_createTimeString = map.get("CreateTime");
			String m_messType = map.get("MsgType");
			
			System.err.println("------------------------------------------------");
			System.err.println(m_fromUserName+"|| "+m_toUserNameString+"|| "+m_createTimeString+"|| "+m_messType);
			System.err.println("------------------------------------------------");
			
			//String m_msgId = map.get("MsgId");
			Message_Text text = new Message_Text();
			text.setToUserNameString(m_fromUserName);
			text.setFormUserNameString(m_toUserNameString);
			text.setCreateTime(new Date().getTime());
			text.setMessageType(MessageUtil.RESP_MESSAGETYPE_TEXT);
			
			if (m_messType.equals("text")) {
				// Text
				respContent = "Text";
			} else if (m_messType.equals("image")) {
				// Image
				respContent = "Image";
			} else if (m_messType.equals("voice")) {
				// voice
				respContent = "voice";
			} else if (m_messType.equals("vidio")) {
				// video
				respContent = "video";
			} else if (m_messType.equals("location")) {
				// location
				respContent = "location";
			} else if (m_messType.equals("link")) {
				// link
				respContent = "link";
			} else {
				// WTF
				;
			}
			text.setContentString(respContent);
			respXMLString = MessageUtil.messageToXML(text);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return respXMLString;
	}
}
